package org.dawfinn.droiditarian;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class Help extends Activity {
	
	private ListView helpItems;
	
	@Override
	public void onCreate(Bundle savedInstance) {
		super.onCreate(savedInstance);
		this.setContentView(R.layout.help);
		
		helpItems = (ListView)findViewById(R.id.helpItemList);
		Resources res = this.getResources();
		String[] headerStrings = res.getStringArray(R.array.help_titles);
		String[] textStrings = res.getStringArray(R.array.help_text);
		
		List<Map<String, String>> listItems = getHelpItems(headerStrings, textStrings);
		SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.help_item,
				new String[] {"header", "text"}, new int[] {R.id.helpMenuItem, R.id.helpContent});
		helpItems.setAdapter(adapter);
	}
	
	/**
	 * @precondition headers and text are the same length
	 */
	private List<Map<String, String>> getHelpItems(String[] headers, String[] text) {
		List<Map<String, String>> items = new ArrayList<Map<String, String>>();
		for (int headerNum = 0; headerNum < headers.length; headerNum++) {
			Map<String, String> thisItem = new HashMap<String, String>();
			thisItem.put("header", headers[headerNum]);
			thisItem.put("text", text[headerNum]);
			items.add(thisItem);
		}
		return items;
	}
}
